#include "window_language.h"
#include "window_message.h"
#include "lvgl.h"
#include "window_image.h"
#include "language.h"




#define LANGUAGE_NUM               2
#define LANGUAGE_MAX_LENGTH        25
const char language_txt[LANGUAGE_NUM][LANGUAGE_MAX_LENGTH]=
{
	"中文",
	"English",
	//"français",  
	//"日本語", 
};
static void my_event_cb(lv_event_t * event)
{
	
	//printf("LV_EVENT_LONG_PRESSED\r\n");
	#if 1
	lv_dir_t  dir = lv_indev_get_gesture_dir(lv_indev_get_act());//获得手势的方向
	
		//判断当前的对象
	  lv_obj_t * obj = lv_event_get_target(event);
	
	  lv_indev_t * indev = lv_indev_get_act(); //获取当前的坐标
    if(indev == NULL)  return;
	if(LV_DIR_RIGHT  == dir)  
	{
		lv_obj_del(obj);  //删除当前对象
		printf("LV_DIR_RIGHT\r\n");
	}else if(LV_DIR_LEFT  == dir)
	{
		
		
	  printf("LV_DIR_LEFT\r\n");
	}
	
  #endif	
}	



static void check_box_event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);
    if(code == LV_EVENT_VALUE_CHANGED) {
        const char * txt = lv_checkbox_get_text(obj);
        const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked";
        LV_LOG_USER("%s: %s", txt, state);
    }
}



static lv_style_t style_radio;
static lv_style_t style_radio_chk;
static uint32_t active_index_1 = 0;
static uint32_t active_index_2 = 0;

static void radio_event_handler(lv_event_t * e)
{
    uint32_t * active_id = lv_event_get_user_data(e);
    lv_obj_t * cont = lv_event_get_current_target(e);
    lv_obj_t * act_cb = lv_event_get_target(e);
    lv_obj_t * old_cb = lv_obj_get_child(cont, *active_id);

    /*Do nothing if the container was clicked*/
    if(act_cb == cont) return;

    lv_obj_clear_state(old_cb, LV_STATE_CHECKED);   /*Uncheck the previous radio button*/
    lv_obj_add_state(act_cb, LV_STATE_CHECKED);     /*Uncheck the current radio button*/

    *active_id = lv_obj_get_index(act_cb);

    LV_LOG_USER("Selected radio buttons: %d, %d", (int)active_index_1, (int)active_index_2);
}


static void radiobutton_create(lv_obj_t * parent, const char * txt)
{
    lv_obj_t * obj = lv_checkbox_create(parent);
	  lv_style_set_text_font(&style_radio, &language_36);                   //璁剧疆瀛椾綋
	  
		lv_obj_set_style_text_font(obj, &language_36, 0);
    lv_checkbox_set_text(obj, txt);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE);

	 

    lv_obj_add_style(obj, &style_radio, LV_PART_INDICATOR);
    lv_obj_add_style(obj, &style_radio_chk, LV_PART_INDICATOR | LV_STATE_CHECKED);
}



void window_language_init(void)
{
    lv_style_init(&style_radio);
    lv_style_set_radius(&style_radio, LV_RADIUS_CIRCLE);

    lv_style_init(&style_radio_chk);
    lv_style_set_bg_img_src(&style_radio_chk, NULL);

    uint32_t i;

		
		
		
		
		
		
	 lv_obj_t* obj =lv_obj_create(lv_scr_act());	  //源莰莵幕讛谐
	 lv_obj_set_style_bg_color(obj, lv_color_make(0,0,0), 0);//狮變殉薨視色为蹥色
	 lv_obj_set_size(obj,LV_HOR_RES_MAX, LV_VER_RES_MAX);
	
	  static lv_style_t lv_style1;              //微铱夜式
    lv_style_init(&lv_style1);           // 缘始郫写钮夜式
	  //lv_style_set_radius(&lv_style, 20); // 狮變夜式圆迖邸讏
	  //lv_obj_set_style_bg_color(list1, lv_color_make(0,0,0), 0);//狮變殉薨視色为蹥色
	  lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);  //取谢诙织偷袛示
    //lv_obj_set_style_bg_opa(list1,LV_OPA_60,0);               //狮變透姆讏
		lv_style_set_bg_color(&lv_style1,lv_color_make(0,0,0));
	  lv_style_set_text_align(&lv_style1,LV_TEXT_ALIGN_LEFT);
		
		lv_style_set_text_color(&lv_style1,lv_color_make(0xff,0xff,0xff));
		lv_style_set_text_color_filtered(&lv_style1,lv_color_make(0xff,0,0));
	  lv_style_set_pad_all(&lv_style1,0); //菍煤只俣壹邧
  	lv_style_set_border_color(&lv_style1,lv_color_make(0,0,0)); //狮變覠酄惨暽?
	  lv_obj_add_style(obj, &lv_style1, 0);
		
		static lv_style_t checkbox;              //微铱夜式
    lv_style_init(&checkbox);           // 缘始郫写钮夜式

		

    lv_obj_t * cont1 = lv_obj_create(obj);
		
		
		
		//lv_style_set_radius(&lv_style, 20); // 狮變夜式圆迖邸讏
	  //lv_obj_set_style_bg_color(list1, lv_color_make(0,0,0), 0);//狮變殉薨視色为蹥色
	  lv_obj_set_scrollbar_mode(cont1, LV_SCROLLBAR_MODE_OFF);  //取谢诙织偷袛示
    //lv_obj_set_style_bg_opa(list1,LV_OPA_60,0);               //狮變透姆讏
		lv_style_set_bg_color(&checkbox,lv_color_make(0,0,0));
	  lv_style_set_text_align(&checkbox,LV_TEXT_ALIGN_LEFT);
		
		lv_style_set_text_color(&checkbox,lv_color_make(0xff,0xff,0xff));
		lv_style_set_text_color_filtered(&checkbox,lv_color_make(0,0,0));
		lv_style_set_pad_all(&checkbox,0); //菍煤只俣壹邧
		lv_style_set_border_color(&checkbox,lv_color_make(0,0,0)); //狮變覠酄惨暽?
		lv_obj_add_style(cont1, &checkbox, 0);
		
		
		
		
		
    lv_obj_set_flex_flow(cont1, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_size(cont1, 220, 220);
    lv_obj_add_event_cb(cont1, radio_event_handler, LV_EVENT_CLICKED, &active_index_1);
    //lv_obj_set_pos(cont1,100,100);
		lv_obj_center(cont1);
		
		
    for(i = 0; i < LANGUAGE_NUM; i++) {
			
			
			
        //lv_snprintf(buf, sizeof(buf), "A %d", (int)i + 1);
        radiobutton_create(cont1, &language_txt[i][0]);

    }
    /*Make the first checkbox checked*/
    lv_obj_add_state(lv_obj_get_child(cont1, 0), LV_STATE_CHECKED);


	lv_obj_add_event_cb(obj,my_event_cb,LV_EVENT_PRESSING,NULL);   //添加对象回调函数

}